package com.hzz.service.area;

import com.hzz.api.area.IAreaService;
import com.hzz.dao.area.IAreaDao;
import com.hzz.dto.area.AreaDto;
import com.hzz.entity.area.Area;
import com.hzz.framework.SysErrorCode;
import com.hzz.framework.annotation.FeignService;
import com.hzz.framework.exception.ServiceException;
import com.hzz.framework.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@FeignService
@Slf4j
public class AreaService extends BaseService implements IAreaService {
    @Autowired
    IAreaDao areaDao;

    @Override
    public List<AreaDto> findDataIsList(AreaDto dto) throws Exception {
        List<AreaDto> results = null;
        try {
            Area entity = copyTo(dto, Area.class);
            results = copyTo(areaDao.findDataIsList(entity), AreaDto.class);
        } catch (Exception e) {
            log.error("信息[列表]查询异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return results;
    }

    @Override
    public AreaDto findDataById(Long id) throws Exception {
        AreaDto result = null;
        try {
            Area entity = new Area();
            entity.setId(id);
            result = copyTo(areaDao.selectByPrimaryKey(entity), AreaDto.class);
        } catch (Exception e) {
            log.error("信息查询异常!", e);
            throw new ServiceException(SysErrorCode.defaultError, e);
        }
        return result;
    }

}
